Harden dailyInfo validation, coordinator parsing, per-day sensor gating, and improve test isolation#67
Conversation
Summary of ChangesHello @eXPerience83, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and reliability of the pollen levels integration by implementing stricter data validation, improving error handling for malformed API responses, and refining sensor creation logic. It also addresses potential unique ID collisions and improves the overall stability of the test suite through better isolation, ensuring a more predictable and resilient user experience. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a73370ef2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Code Review
The pull request significantly improves the robustness of the integration by hardening the validation of the dailyInfo payload in both the config flow and the coordinator. It also correctly gates the creation of forecast sensors based on the available forecast days and improves test isolation using monkeypatch. The increased precision for unique IDs is a welcome change for accuracy, though it requires consideration for existing entries to avoid duplicate configurations.
User description
Motivation
dailyInfopayloads from causing day-offset reindexing or accidental entity churn by aligning config-flow validation with runtime parsing rules.dailyInfopayloads as malformed and either preserves prior data or fails cleanly on first refresh.forecast_daysoptions do not permit them and reduce accidental unique-id collisions for nearby coordinates.Description
dailyInfois a non-empty list of dict objects and logs/wraps the error via the existingcannot_connectplaceholder (custom_components/pollenlevels/config_flow.py).dailyInfoas invalid when it is not a list or when any list item is not a dict, preserves the last successful dataset when present, and raisesUpdateFailedon first refresh when no prior data exists (custom_components/pollenlevels/coordinator.py).datasnapshot for iteration and skips creating*_d1/*_d2sensors when runtime flags andforecast_daysdisallow them, and proactively cleans up stale per-day entities (custom_components/pollenlevels/sensor.py).normalize_sensor_modeand gatescreate_d1/create_d2by the effectiveforecast_days, and config-flow coordinate unique-id precision was increased to 6 decimals while rejecting whitespace-only API keys (custom_components/pollenlevels/__init__.pyandconfig_flow.py).dailyInfoshapes; coordinator tests for invalid/mixeddailyInfobehavior and preservation of last data; sensor test ensuring disabled D+ sensors are not recreated; and setup tests were switched to scopedmonkeypatchusage to avoid persistent module reassignment (tests/*).CHANGELOG.mdupdated under the existing1.9.3section to reflect these hardening and test-isolation changes (no version bump).Testing
ruff check --fix --select Iandruff checkon the modified files, and they passed.blackand applied the reformat to the targeted files successfully.pytest -qand all tests passed (138 passed).Codex Task
PR Type
Enhancement, Bug fix, Tests
Description
Hardened
dailyInfovalidation in config flow and coordinator to reject non-list/non-dict payloads and preserve last successful dataGated D+1/D+2 sensor creation by effective
forecast_daysto prevent disabled sensors from being recreatedIncreased unique-id precision from 4 to 6 decimals to reduce collisions for nearby coordinates
Normalized stored forecast sensor mode values during setup and improved test isolation with scoped monkeypatching
Diagram Walkthrough
File Walkthrough
__init__.py
Gate per-day sensor creation by forecast dayscustom_components/pollenlevels/init.py
normalize_sensor_mode()call to handle legacy/whitespace-paddedforecast mode values
create_d1andcreate_d2flags by minimumforecast_daysthresholds (2 and 3 respectively)
ConfigEntryAuthFailedconfig_flow.py
Strengthen dailyInfo validation and unique-id precisioncustom_components/pollenlevels/config_flow.py
reduce collisions for nearby locations
dailyInfovalidation to require non-empty list of dictobjects instead of just checking presence
dailyInfostructure (list + all itemsare dicts)
coordinator.py
Validate dailyInfo structure and preserve last datacustom_components/pollenlevels/coordinator.py
dailyInfoto ensure it is a list with alldict items
dailyInfostructures as malformed instead ofcompacting/reindexing
UpdateFailedonly on first refreshdailyInfosensor.py
Skip disabled per-day sensors during setupcustom_components/pollenlevels/sensor.py
datasnapshot instead ofcoordinator.data directly
*_d1and*_d2keys whenallow_d1/allow_d2flags are False
test_config_flow.py
Add dailyInfo validation and unique-id precision teststests/test_config_flow.py
dailyInfoin HTTP 200 response(should set
cannot_connecterror)dailyInfolist with non-dict items (shouldset
cannot_connecterror)unique-ids with 6-decimal precision
_SequenceSessionfor multiple HTTP calls insteadof single-call stub
test_init.py
Improve test isolation and add setup validation teststests/test_init.py
monkeypatch.setattr()calls to improve test isolationwhitespace-padded values
forecast_daysis insufficient
test_sensor.py
Add coordinator and sensor setup validation teststests/test_sensor.py
dailyInfotype raisingUpdateFailedon firstrefresh
dailyInfoitems preserving last successfulcoordinator data
dailyInfoitems being treated asmalformed payload
when
forecast_daysdisallows themCHANGELOG.md
Document validation hardening and test improvementsCHANGELOG.md
dailyInfovalidation in config flow andcoordinator
normalization
coverage